package controllers

import (
	//"github.com/astaxie/beego"
	//"fmt"
	"jiabo/appframework/libs/taskmanage"
)

type OrgController struct {
	RootController
}

func (this *OrgController) Get() {
	this.CheckSession()

	//this.Ctx.Request.ParseForm()
	this.Data["fullname"] = this.GSession("fullname")
	this.Data["m1"] = "arrow"
	this.Data["m2"] = "arrow"
	this.Data["m3"] = "selected"
	this.Data["m4"] = "arrow"
	this.Data["m33"] = "start active"
	this.Layout = "layout.html"
	this.TplNames = "orgization.html"

}

func (this *OrgController) Post() {
	username := this.CheckSession()
	userorgs, _ := taskmanage.GetOrgnizationByUsername(username.(string))
	var orgs []string

	for _, uo := range userorgs {
		orgs = append(orgs, uo.OrgOid)
	}

	orgs2, _ := taskmanage.GetOrgnizationByOids(orgs)

	t := ""
	for i, myorg := range orgs2 {
		color := "blue"
		if i%4 == 0 {
			t = t + `<div class="row-fluid"  >`
		}
		if i%5 == 0 {
			color = "blue"
		}
		if i%5 == 1 {
			color = "green"
		}
		if i%5 == 2 {
			color = "purple"
		}
		if i%5 == 3 {
			color = "yellow"
		}
		if i%5 == 4 {
			color = "red"
		}
		t = t + `<div class="span3 responsive" data-tablet="span6" data-desktop="span3">`
		t = t + `<div class="dashboard-stat ` + color + `">`
		t = t + `<div class="visual">`
		t = t + `<i class="icon-group"></i></div>`
		t = t + `<div class="details"><div class="number">`
		t = t + myorg.OrgName
		t = t + `</div><div class="desc">创建人:` + myorg.Owner + `</div></div><a class="more" href="/orgdetail?oid=` + myorg.Oid + `">`
		t = t + `详细信息 <i class="m-icon-swapright m-icon-white"></i></a></div></div>`

		if i%4 == 3 {
			t = t + `</div>`
		}
	}
	this.Ctx.WriteString(t)
}
